﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapWASTGA(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWASTGA(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWASTGA(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWASTGA(ref dwLocal, dwData);

            InsertWASTGA(dwLocal);
            UpdateWASTGA(dwLocal);
        }
        public void InsertWASTGA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO WASTGA(WAGMANDANT, WAGKUNDNR, WAGWERK, WAGABT, WAGART, WAGVAR, WAGWCOL, WAGPSA, WAGPOS, WAGFOLGEPOS, WAGGART, WAGGVAR, WAGGFARBE, WAGFDZ, WAGABFKZ, WAGABF, WAGABFLG, WAGKGNET, WAGKGBRUT, WAGDISPOKZ, WAGBEM, WAGEAFAKTOR, WAGGRLFDM, WAGKZQM, WAGPROZWG, WAGABFALL, WAGAUFM, WAGANT, WAGEINL, WAGSPANNV, WAGSPANNB, WAGSPANNF, WAGVARKZ, WAGNA1, WAGNA2, WAGNA3, WAGNA4, WAGNA5, WAGNP, WAGWEAVIN, WAGWEEMBR, WAGFLOATING, WAGFL, WAGFLNA1, WAGFLNA2, WAGFLNA3, WAGFLNA4, WAGFLNA5, WAGFLNP, WAGFILLER) "
                + " VALUES (:WAGMANDANT, '00000000', '   ', '   ', :WAGART, :WAGVAR, :WAGWCOL, '1', :WAGPOS, :WAGFOLGEPOS, '                    ', '   ', '          ', 0, ' ', 0, 0, 0, 0, 'B', '          ', 0, 0, ' ', 0, 0, '  ', 0, 0, 0, 0, '00', ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, '  ', 0, 0, 0, 0, 0, 0, '                                              ')";
            or1.Parameters.Add("WAGMANDANT", OracleType.NVarChar).Value = dwData["WAGMANDANT"].ToString();
            or1.Parameters.Add("WAGART", OracleType.NVarChar).Value = dwData["WAGART"].ToString();
            or1.Parameters.Add("WAGVAR", OracleType.NVarChar).Value = dwData["WAGVAR"].ToString();
            or1.Parameters.Add("WAGWCOL", OracleType.NVarChar).Value = dwData["WAGWCOL"].ToString(); ;
            or1.Parameters.Add("WAGPOS", OracleType.NVarChar).Value = dwData["WAGPOS"].ToString();
            or1.Parameters.Add("WAGFOLGEPOS", OracleType.Number).Value = dwData["WAGFOLGEPOS"].ToString();
            setResult = Connect2Proxy(or1);
        }
        public void DeleteWASTGA(string client, string art, string var, string color)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE WASTGA WHERE  "
            + "  WAGMANDANT=:WAGMANDANT AND WAGART=:WAGART AND WAGVAR=:WAGVAR AND WAGWCOL=:WAGWCOL";
            or1.Parameters.Add("WAGMANDANT", OracleType.NVarChar).Value = client;
            or1.Parameters.Add("WAGART", OracleType.NVarChar).Value = art;
            or1.Parameters.Add("WAGVAR", OracleType.NVarChar).Value = var;
            or1.Parameters.Add("WAGWCOL", OracleType.NVarChar).Value = color;
            Connect2Proxy(or1);
        }
        public DataSet QueryWASTGA(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WASTGA WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM WASTGA WHERE  "
                        + "  WAGMANDANT=:WAGMANDANT AND WAGART=:WAGART AND WAGVAR=:WAGVAR AND WAGWCOL=:WAGWCOL AND WAGPOS=:WAGPOS AND WAGFOLGEPOS=:WAGFOLGEPOS";
                    or1.Parameters.Add("WAGMANDANT", OracleType.NVarChar).Value = dwData["WAGMANDANT"].ToString();
                    or1.Parameters.Add("WAGART", OracleType.NVarChar).Value = dwData["WAGART"].ToString();
                    or1.Parameters.Add("WAGVAR", OracleType.NVarChar).Value = dwData["WAGVAR"].ToString();
                    or1.Parameters.Add("WAGWCOL", OracleType.NVarChar).Value = dwData["WAGWCOL"].ToString(); ;
                    or1.Parameters.Add("WAGPOS", OracleType.NVarChar).Value = dwData["WAGPOS"].ToString(); ;
                    or1.Parameters.Add("WAGFOLGEPOS", OracleType.Number).Value = dwData["WAGFOLGEPOS"].ToString();
                    break;
                case 2:
                           or1.CommandText = "SELECT * FROM WASTGA WHERE  "
                        + "  WAGMANDANT=:WAGMANDANT AND WAGPSA='1' AND WAGART=:WAGART AND WAGVAR=:WAGVAR AND WAGWCOL=:WAGWCOL  ";
                    or1.Parameters.Add("WAGMANDANT", OracleType.NVarChar).Value = dwData["WAGMANDANT"].ToString();
                    or1.Parameters.Add("WAGART", OracleType.NVarChar).Value = dwData["WAGART"].ToString();
                    or1.Parameters.Add("WAGVAR", OracleType.NVarChar).Value = dwData["WAGVAR"].ToString();
                    or1.Parameters.Add("WAGWCOL", OracleType.NVarChar).Value = dwData["WAGWCOL"].ToString(); ; 
                    break;
                case 4:
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "SELECT DISTINCT   WF.*,GSCBEZ FROM WDECK WD RIGHT JOIN WASTGA WF ON"
                        + "  WAGMANDANT=WDMANDANT AND WAGART=WDART AND WAGVAR=WDVAR"
                        +" JOIN GSCOLOR ON GSCART=WAGGART AND GSCVAR=WAGGVAR AND  GSCFARBE= WAGGFARBE"
                        + " WHERE WDMANDANT=:WDMANDANT AND WDSA='K' AND WDTYP='B' AND WDWAKZ='F' AND WDAUFKRS=:WDAUFKRS  AND WDAUFLFD=:WDAUFLFD";
                    or1.Parameters.Add("WDMANDANT", OracleType.NVarChar).Value = dwData["WDMANDANT"].ToString();
                    or1.Parameters.Add("WDAUFKRS", OracleType.NVarChar).Value = dwData["WDAUFKRS"].ToString();
                    or1.Parameters.Add("WDAUFLFD", OracleType.NVarChar).Value = dwData["WDAUFLFD"].ToString();
                    break;
                default:
                    or1.CommandText = "SELECT * FROM WASTGA WHERE  "
                        + "  WAGMANDANT=:WAGMANDANT AND WAGART=:WAGART AND WAGVAR=:WAGVAR";
                    or1.Parameters.Add("WAGMANDANT", OracleType.NVarChar).Value = dwData["WAGMANDANT"].ToString();
                    or1.Parameters.Add("WAGART", OracleType.NVarChar).Value = dwData["WAGART"].ToString();
                    or1.Parameters.Add("WAGVAR", OracleType.NVarChar).Value = dwData["WAGVAR"].ToString();
                    break;
            }


            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "WASTGA";
            }

            setReturn.Merge(Result);
            return setReturn;
        }
        public void UpdateWASTGA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE WASTGA SET "
             + "WAGABFALL=:WAGABFALL,"
            + "WAGAUFM=:WAGAUFM,"
            + "WAGANT=:WAGANT,"
            + "WAGEINL=:WAGEINL,"
            + "WAGSPANNV=:WAGSPANNV,"
            + "WAGSPANNB=:WAGSPANNB,"
            + "WAGSPANNF=:WAGSPANNF,"
            + "WAGVARKZ=:WAGVARKZ,"
            + "WAGNA1=:WAGNA1,"
            + "WAGNA2=:WAGNA2,"
            + "WAGNA3=:WAGNA3,"
            + "WAGNA4=:WAGNA4,"
            + "WAGNA5=:WAGNA5,"
            + "WAGNP=:WAGNP,"
            + "WAGWEAVIN=:WAGWEAVIN,"
            + "WAGWEEMBR=:WAGWEEMBR,"
            + "WAGFLOATING=:WAGFLOATING,"
            + "WAGFL=:WAGFL,"
            + "WAGFLNA1=:WAGFLNA1,"
            + "WAGFLNA2=:WAGFLNA2,"
            + "WAGFLNA3=:WAGFLNA3,"
            + "WAGFLNA4=:WAGFLNA4,"
            + "WAGFLNA5=:WAGFLNA5,"
            + "WAGFLNP=:WAGFLNP,"
            + "WAGFILLER=:WAGFILLER,"
            + "WAGMANDANT=:WAGMANDANT,"
            + "WAGKUNDNR=:WAGKUNDNR,"
            + "WAGWERK=:WAGWERK,"
            + "WAGABT=:WAGABT,"
            + "WAGART=:WAGART,"
            + "WAGVAR=:WAGVAR,"
            + "WAGWCOL=:WAGWCOL,"
            + "WAGPSA=:WAGPSA,"
            + "WAGPOS=:WAGPOS,"
            + "WAGFOLGEPOS=:WAGFOLGEPOS,"
            + "WAGGART=:WAGGART,"
            + "WAGGVAR=:WAGGVAR,"
            + "WAGGFARBE=:WAGGFARBE,"
            + "WAGFDZ=:WAGFDZ,"
            + "WAGABFKZ=:WAGABFKZ,"
            + "WAGABF=:WAGABF,"
            + "WAGABFLG=:WAGABFLG,"
            + "WAGKGNET=:WAGKGNET,"
            + "WAGKGBRUT=:WAGKGBRUT,"
            + "WAGDISPOKZ=:WAGDISPOKZ,"
            + "WAGBEM=:WAGBEM,"
            + "WAGEAFAKTOR=:WAGEAFAKTOR,"
            + "WAGGRLFDM=:WAGGRLFDM,"
            + "WAGKZQM=:WAGKZQM,"
            + "WAGPROZWG=:WAGPROZWG "
            + " WHERE  "
            + "  WAGMANDANT=:WAGMANDANT AND WAGART=:WAGART  AND WAGVAR=:WAGVAR  AND WAGWCOL=:WAGWCOL"
            + " AND WAGPSA=:WAGPSA AND WAGPOS=:WAGPOS AND WAGFOLGEPOS=:WAGFOLGEPOS"
            ;
            or1.Parameters.Add("WAGABFALL", OracleType.NVarChar).Value = dwData["WAGABFALL"].ToString();
            or1.Parameters.Add("WAGAUFM", OracleType.NVarChar).Value = dwData["WAGAUFM"].ToString();
            or1.Parameters.Add("WAGANT", OracleType.NVarChar).Value = dwData["WAGANT"].ToString();
            or1.Parameters.Add("WAGEINL", OracleType.NVarChar).Value = dwData["WAGEINL"].ToString();
            or1.Parameters.Add("WAGSPANNV", OracleType.NVarChar).Value = dwData["WAGSPANNV"].ToString();
            or1.Parameters.Add("WAGSPANNB", OracleType.NVarChar).Value = dwData["WAGSPANNB"].ToString();
            or1.Parameters.Add("WAGSPANNF", OracleType.NVarChar).Value = dwData["WAGSPANNF"].ToString();
            or1.Parameters.Add("WAGVARKZ", OracleType.NVarChar).Value = dwData["WAGVARKZ"].ToString();
            or1.Parameters.Add("WAGNA1", OracleType.NVarChar).Value = dwData["WAGNA1"].ToString();
            or1.Parameters.Add("WAGNA2", OracleType.NVarChar).Value = dwData["WAGNA2"].ToString();
            or1.Parameters.Add("WAGNA3", OracleType.NVarChar).Value = dwData["WAGNA3"].ToString();
            or1.Parameters.Add("WAGNA4", OracleType.NVarChar).Value = dwData["WAGNA4"].ToString();
            or1.Parameters.Add("WAGNA5", OracleType.NVarChar).Value = dwData["WAGNA5"].ToString();
            or1.Parameters.Add("WAGNP", OracleType.NVarChar).Value = dwData["WAGNP"].ToString();
            or1.Parameters.Add("WAGWEAVIN", OracleType.NVarChar).Value = dwData["WAGWEAVIN"].ToString();
            or1.Parameters.Add("WAGWEEMBR", OracleType.NVarChar).Value = dwData["WAGWEEMBR"].ToString();
            or1.Parameters.Add("WAGFLOATING", OracleType.NVarChar).Value = dwData["WAGFLOATING"].ToString();
            or1.Parameters.Add("WAGFL", OracleType.NVarChar).Value = dwData["WAGFL"].ToString();
            or1.Parameters.Add("WAGFLNA1", OracleType.NVarChar).Value = dwData["WAGFLNA1"].ToString();
            or1.Parameters.Add("WAGFLNA2", OracleType.NVarChar).Value = dwData["WAGFLNA2"].ToString();
            or1.Parameters.Add("WAGFLNA3", OracleType.NVarChar).Value = dwData["WAGFLNA3"].ToString();
            or1.Parameters.Add("WAGFLNA4", OracleType.NVarChar).Value = dwData["WAGFLNA4"].ToString();
            or1.Parameters.Add("WAGFLNA5", OracleType.NVarChar).Value = dwData["WAGFLNA5"].ToString();
            or1.Parameters.Add("WAGFLNP", OracleType.NVarChar).Value = dwData["WAGFLNP"].ToString();
            or1.Parameters.Add("WAGFILLER", OracleType.NVarChar).Value = dwData["WAGFILLER"].ToString();
            or1.Parameters.Add("WAGMANDANT", OracleType.NVarChar).Value = dwData["WAGMANDANT"].ToString();
            or1.Parameters.Add("WAGKUNDNR", OracleType.NVarChar).Value = dwData["WAGKUNDNR"].ToString();
            or1.Parameters.Add("WAGWERK", OracleType.NVarChar).Value = dwData["WAGWERK"].ToString();
            or1.Parameters.Add("WAGABT", OracleType.NVarChar).Value = dwData["WAGABT"].ToString();
            or1.Parameters.Add("WAGART", OracleType.NVarChar).Value = dwData["WAGART"].ToString();
            or1.Parameters.Add("WAGVAR", OracleType.NVarChar).Value = dwData["WAGVAR"].ToString();
            or1.Parameters.Add("WAGWCOL", OracleType.NVarChar).Value = dwData["WAGWCOL"].ToString();
            or1.Parameters.Add("WAGPSA", OracleType.NVarChar).Value = dwData["WAGPSA"].ToString();
            or1.Parameters.Add("WAGPOS", OracleType.NVarChar).Value = dwData["WAGPOS"].ToString();
            or1.Parameters.Add("WAGFOLGEPOS", OracleType.NVarChar).Value = dwData["WAGFOLGEPOS"].ToString();
            or1.Parameters.Add("WAGGART", OracleType.NVarChar).Value = dwData["WAGGART"].ToString();
            or1.Parameters.Add("WAGGVAR", OracleType.NVarChar).Value = dwData["WAGGVAR"].ToString();
            or1.Parameters.Add("WAGGFARBE", OracleType.NVarChar).Value = dwData["WAGGFARBE"].ToString();
            or1.Parameters.Add("WAGFDZ", OracleType.NVarChar).Value = dwData["WAGFDZ"].ToString();
            or1.Parameters.Add("WAGABFKZ", OracleType.NVarChar).Value = dwData["WAGABFKZ"].ToString();
            or1.Parameters.Add("WAGABF", OracleType.NVarChar).Value = dwData["WAGABF"].ToString();
            or1.Parameters.Add("WAGABFLG", OracleType.NVarChar).Value = dwData["WAGABFLG"].ToString();
            or1.Parameters.Add("WAGKGNET", OracleType.NVarChar).Value = dwData["WAGKGNET"].ToString();
            or1.Parameters.Add("WAGKGBRUT", OracleType.NVarChar).Value = dwData["WAGKGBRUT"].ToString();
            or1.Parameters.Add("WAGDISPOKZ", OracleType.NVarChar).Value = dwData["WAGDISPOKZ"].ToString();
            or1.Parameters.Add("WAGBEM", OracleType.NVarChar).Value = dwData["WAGBEM"].ToString();
            or1.Parameters.Add("WAGEAFAKTOR", OracleType.NVarChar).Value = dwData["WAGEAFAKTOR"].ToString();
            or1.Parameters.Add("WAGGRLFDM", OracleType.NVarChar).Value = dwData["WAGGRLFDM"].ToString();
            or1.Parameters.Add("WAGKZQM", OracleType.NVarChar).Value = dwData["WAGKZQM"].ToString();
            or1.Parameters.Add("WAGPROZWG", OracleType.NVarChar).Value = dwData["WAGPROZWG"].ToString();
            Connect2Proxy(or1);
        }
    }
}
